function [Accuracy,p_Accuracy]=fingerprinting(mat1,mat2,permutation,group1_number)
%����������ָ�Ƶ��㷨��mat1��mat2
%Ϊͬһ�鱻�Ե�ǰ��ͺ�������������ֱ�Ĳ��permutation���û�������group1_number������
%%
%ɾ��0���ӿ�����ٶ�
[a,b]=find(mat1==0);
mat1(:,b)=[];
mat2(:,b)=[];
for p=1:permutation%�û�����
    if p>1
        c_mat1 = mat1(randperm(group1_number),:);
    else
        c_mat1= mat1;
    end
    %��һ��Ϊ��ʽ��ģ�ͣ�֮��Ķ����û����������
    count1 = 0;%�ۼ�1-2��ƥ����ȷ����
    count2 = 0;%�ۼ�2-1��ƥ����ȷ����
    
    for i=1:group1_number;
        % using session 1 as database
        tt_corr = mat2(i,:);
        tt_to_all = corr(tt_corr', c_mat1');   %���ĸ�����0.4449
        [va, va_id] = max(tt_to_all);    %�ó���va��0.4449��va_id��Ӧ����ֵ     va_id��4
        if( i == va_id)
            count1 = count1+1;
        end
        clear tt_corr tt_to_all va va_id
        % using session 2 as database
        tt_corr = c_mat1(i,:);
        tt_to_all = corr(tt_corr', mat2');
        [va, va_id] = max(tt_to_all);
        if( i == va_id)
            count2 = count2+1;
        end
    end
    rate(p) =((count1+count2)/group1_number)/2;
    
end
Accuracy=rate(1);
p_Accuracy=mean(rate(1)<=rate);
end


